package com.fernfx.xingtan.my.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.fernfx.xingtan.R;
import com.fernfx.xingtan.my.entity.DiamondsHistroyInfoEntity;
import com.fernfx.xingtan.utils.CollectionUtil;
import com.fernfx.xingtan.utils.OtherUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by admin on 2018/8/16.
 * 钻石记录adapter
 */

public class DiamondsHistroyInfoAdapter extends RecyclerView.Adapter<DiamondsHistroyInfoAdapter.MasonryView> {
    private List<DiamondsHistroyInfoEntity.ObjBean.RecordsBean>  datas;
    private Context context;

    public DiamondsHistroyInfoAdapter(Context context){
        this.context = context;
    }

    public void setDatas(List<DiamondsHistroyInfoEntity.ObjBean.RecordsBean>  datas){
        if (CollectionUtil.isEmpty(datas)) {
            this.datas = new ArrayList<>(0);
        }
        this.datas = datas;
    }

    @NonNull
    @Override
    public MasonryView onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = View.inflate(context,R.layout.adapter_my_purse_diamonds_item,null);
        MasonryView masonryView =new MasonryView(view);
        return masonryView;
    }

    @Override
    public void onBindViewHolder(@NonNull MasonryView holder, int position) {
        //get list item
        DiamondsHistroyInfoEntity.ObjBean.RecordsBean recordsBean = datas.get(position);
        if (recordsBean == null) {
            return;
        }

        //set value
        holder.title1TextTv.setText(OtherUtil.checkEmptyDefault(recordsBean.getGetOrPay()));
        holder.title1ContentTv.setText(OtherUtil.checkEmptyDefault(recordsBean.getAbsAmount()));
        holder.title2TextTv.setText(OtherUtil.checkEmptyDefault(recordsBean.getCreateTime()));
        holder.title2ContentTv.setText(OtherUtil.checkEmptyDefault(recordsBean.getAmount()));
    }

    @Override
    public int getItemCount() {
        return datas.size();
    }


    class MasonryView extends RecyclerView.ViewHolder {
        TextView title1TextTv;
        TextView title1ContentTv;
        TextView title2TextTv;
        TextView title2ContentTv;

        public MasonryView(View itemView) {
            super(itemView);
            title1TextTv = (TextView) itemView.findViewById(R.id.title1_text_tv);
            title1ContentTv = (TextView) itemView.findViewById(R.id.title1_content_tv);
            title2TextTv = (TextView) itemView.findViewById(R.id.title2_text_tv);
            title2ContentTv = (TextView) itemView.findViewById(R.id.title2_content_tv);
        }

    }
}
